import React, { Component, createRef } from 'react';
import CChild from './CChild'; 

export default class CParent extends Component {
	constructor (props) {
		super(props);
		//用于调用子组件函数-1
		this.test01Ref = createRef();
	}
	state = {
		msg1: 'h111',
		msg2: 'h222',
	}
	pFn = () => {
		console.log('CParent', this.state);
		//用于调用子组件函数-2
		this.test01Ref.current.cFn(this.state);
	}
	// 渲染函数
    render() {
    	return (
			<div>
			    <div onClick={this.pFn}>CParent:点击触发子组件事件</div>
				<CChild ref={this.test01Ref} ms1={this.state.msg1} ms2={this.state.msg2}></CChild>
			</div>
		);
    }
};
